#include "poultry.h"

Poultry::Poultry()
{
    direction=3+rand()%3;
    nextProductionTime=clock()+5000;
}

QSize Poultry::getSize()
{
    return poultrySize;
}

void Poultry::changeDirection()
{
    this->direction*=-1;
}

void Poultry::resetTime(int timeLen=5000)
{
    nextProductionTime=clock()+timeLen;
}

Product *Poultry::produce(int line, int timeLen=5000)
{
    nextProductionTime=clock()+timeLen;
    int r=rand()%7;
    int x=topLeft.x()+(poultrySize.width()-productSize.width())/2;
    if(r<=1) return new Shit(QPoint(x,line+1));
    return new Egg(QPoint(x,line+1));
}

QRegion Poultry::getRegion()
{
    static const QBitmap bm=QBitmap::fromImage(QImage(imagesDirectory+"giacam.bmp","BMP").scaled(poultrySize.width(),poultrySize.height()),Qt::MonoOnly);
    static const QRegion region(bm);
    return region.translated(topLeft);
}
